<?php
/*
 * @Author: SunnyJ
 * @Date: 2021-05-06 22:37:29
 * @LastEditors: SunnyJ
 * @LastEditTime: 2021-06-02 11:51:50
 */

namespace app\api\controller;
use think\Db;

class Area extends Base2 {

    // 获取一级地址
    public function provinces($token) {
        // 验证token与platformCode
        $auth = Auth2::check_token($token,$platformCode);
        if (!$auth['result']) {
            return $this -> create('', $auth['msg'], false);
        }
        $data = Db::name('region') -> field('name,id') -> where('level',1) -> order('sort asc') -> select();
        $result = array();
        foreach ($data as &$v) {
            $va = array($v['name'] => $v['id']);
            $result[] = $va;
        }
        return $this -> create($result,'数据请求成功');
    }

    // 获取二级地址
    public function cities($token,$id) {
        // 验证token与platformCode
        $auth = Auth2::check_token($token,$platformCode);
        if (!$auth['result']) {
            return $this -> create('', $auth['msg'], false);
        }
        $data = Db::name('region') -> field('name,id') -> where('pid',$id) -> order('sort asc') -> select();
        $result = array();
        foreach ($data as &$v) {
            $va = array($v['name'] => $v['id']);
            $result[] = $va;
        }
        return $this -> create($result,'数据请求成功');
    }

    // 获取三级地址
    public function getCounty($token,$id) {
        // 验证token与platformCode
        $auth = Auth2::check_token($token,$platformCode);
        if (!$auth['result']) {
            return $this -> create('', $auth['msg'], false);
        }
        $data = Db::name('region') -> field('name,id') -> where('pid',$id) -> order('sort asc') -> select();
        $result = array();
        foreach ($data as &$v) {
            $va = array($v['name'] => $v['id']);
            $result[] = $va;
        }
        return $this -> create($result,'数据请求成功');
    }
}


?>